package cn.fyg.service.finance.util;

import java.security.MessageDigest;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import sun.misc.BASE64Encoder;

@SuppressWarnings("restriction")
public class CryptoUtil {
	private static Logger logger = LogManager.getLogger(CryptoUtil.class.getName()); 
	
	/**
	 * MD5 加密算法
	 * @param strSrc
	 * @return
	 */
	public static String encrypt(String strSrc) {

		byte btKey[] = new byte[strSrc.getBytes().length + 1];
		System.arraycopy(strSrc.getBytes(), 0, btKey, 0,strSrc.getBytes().length);
		String strEncode = null;

		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(btKey);
			byte btDigest[] = md.digest();
			BASE64Encoder encoder = new BASE64Encoder();
			strEncode = encoder.encode(btDigest);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return strEncode;
	}
}
